package cn.wolfcode.trip.api.controller;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.query.CommentQueryObject;
import cn.wolfcode.trip.base.service.IStrategyDetailCommentService;
import cn.wolfcode.trip.base.service.IStrategyDetailService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/strategyDetails")
public class StrategyDetailController {

    @Autowired
    private IStrategyDetailService strategyDetailService;
    @Autowired
    private IStrategyDetailCommentService strategyDetailCommentService;

    @GetMapping("/{id}")
    public StrategyDetail getById(@PathVariable Long id) {
        return strategyDetailService.getById(id);
    }

    //浏览点击数量
    @PutMapping
    public JsonResult updateBrowseNum(StrategyDetail strategyDetail)
    {
        JsonResult result = new JsonResult();
        try {
            //关联当前用户
            strategyDetailService.updateBrowseNum(strategyDetail);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    /**
     * 查询指定攻略文章下的所有评论信息
     *
     * @param qo
     * @return
     */
    @GetMapping("/{strategyDetailId}/comments")
    public PageInfo<Strategy> listCommonds(CommentQueryObject qo) {
        PageInfo pageInfo = strategyDetailCommentService.query(qo);
        return pageInfo;
    }

}
